package thread.bank;

public class Bank {
	public void doTransaction(Transaction transaction) {
		int balance = transaction.getAccount().getBalance();
		switch (transaction.getTransactionType()) {
		case Transaction.CREDIT:
			try {
				Thread.sleep(100);
			} catch (InterruptedException ex) {
				ex.printStackTrace();
			}
			break;
		case Transaction.DEBIT:
			try {
				Thread.sleep(200);
			} catch (InterruptedException ex) {
				ex.printStackTrace();
			}
			balance -= transaction.getAmount();
			break;
		default:
			System.out.println("Invalid transaction");
			System.exit(1);
		}
		transaction.getAccount().setBalance(balance);
	}
}
